package cn.hackcloud.config.config;

import cn.hackcloud.config.annotation.EnableGlobalConfig;
import cn.hackcloud.config.scope.RefreshScopeRegistry;
import cn.hackcloud.config.zookeeper.CuratorUtil;
import org.springframework.context.annotation.ImportSelector;
import org.springframework.core.type.AnnotationMetadata;

import java.util.Map;

public class ConfigImportSelector implements ImportSelector {
    @Override
    public String[] selectImports(AnnotationMetadata metadata) {
        Map<String, Object> attributes = metadata.getAnnotationAttributes(EnableGlobalConfig.class.getName(), true);
        Object mode = attributes.get("mode");
        if ("zk".equals(mode.toString())) {
            return new String[]{RefreshScopeRegistry.class.getName(), CuratorUtil.class.getName()};
        } else {
            return new String[0];
        }
    }
}
